home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Other Stuff
/
Other Stuff ’97
/
PowerOS Development
/
basic kernel source
/
dprintf.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-06-26
|
2KB
|
102 lines
/*
dprintf.c
a source file for PowerOS
copyright 1996-1997 by Ben Martz
all rights reserved world wide
ANY AND ALL MODIFICATIONS TO THIS SOURCE MUST CREDIT THE ORIGINAL
AUTHOR, BEN MARTZ (benmartz@ic.net), AND MUST BE GIVEN TO THE AUTHOR
FOR INTEGRATION INTO THE MAIN PowerOS SOURCE TREE. THANK YOU FOR YOUR
COOPERATION!
*/
#include "poweros_types.h"
#include "debug_console.h"
#include "dprintf.h"
#include <stdarg.h>
void dprintstr(char *s);
void dprintnum(unsigned int num, int base);
void dprintf(char *format, ...) {
__gnuc_va_list args;
char *pos, c, f;
int num = 0, islong = 0;
char *s;
u_long unum = 0;
va_start(args,format);
pos = format;
while(c = *pos++) {
if(c == '%') {
f = *pos++;
switchagain:
switch(f) {
case '%':
cputchar('%');
break;
case 'c':
num = va_arg(args,int);
cputchar(num);
break;
case 's':
s = va_arg(args,char *);
dprintstr(s);
break;
case 'd':
num = va_arg(args,int);
if(num < 0) {
num *= -1;
cputchar('-');
}
dprintnum(num,10);
break;
case 'x':
num = va_arg(args,int);
dprintnum(num,16);
break;
case 'l':
f = *pos++;
goto switchagain;
break;
case 'u':
unum = va_arg(args,int);
dprintnum(num,10);
break;
}
} else {
cputchar(c);
}
}
va_end(args);
}
void dprintstr(char *s) {
char c;
while(c = *s++) cputchar(c);
}
const char num_chars[] = "0123456789abcdef";
void dprintnum(unsigned int num, int base) {
char numbuf[16];
char *tmp;
if(num == 0) {
cputchar('0');
return;
}
tmp = numbuf+15;
*tmp = '\0';
while(num > 0) {
*--tmp = num_chars[num % base];
num /= base;
}
dprintstr(tmp);
}